package pl.maciejziarko.mshare.dto.converters;

import org.springframework.stereotype.Component;
import pl.maciejziarko.mshare.domain.Account;
import pl.maciejziarko.mshare.domain.Resource;
import pl.maciejziarko.mshare.dto.ResourceDTO;

/**
 * @author Maciej Ziarko
 */
@Component
public final class ResourceDTOConverter {
    public Resource convert(ResourceDTO formObject) {
        Resource resource = new Resource();
        resource.setData(formObject.getData());
        resource.setId(formObject.getId());
        resource.setMimeType(formObject.getMimeType());
        resource.setResourceType(formObject.getResourceType());
        resource.setName(formObject.getName());
        resource.setSize(formObject.getSize());
        return resource;
    }

    public ResourceDTO convert(Resource resource) {
        ResourceDTO resourceDTO = new ResourceDTO();
        resourceDTO.setData(resource.getData());
        resourceDTO.setId(resource.getId());
        resourceDTO.setMimeType(resource.getMimeType());
        resourceDTO.setResourceType(resource.getResourceType());
        resourceDTO.setName(resource.getName());
        resourceDTO.setSize(resource.getSize());
        resourceDTO.setOwner(resource.getOwner().getUsername());
        return resourceDTO;
    }
}
